<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <table
      width="800px"
      style="height: 500px"
      cellpadding="0"
      cellspacing="0"
      border="1"
    >
      <thead>
        <tr>
          <th>序号</th>
          <th>姓名</th>
          <th>年龄</th>
        </tr>
      </thead>
      <tr>
        <td>1</td>
        <td>张三</td>
        <td>20</td>
      </tr>
      <tr>
        <td>2</td>
        <td>李四</td>
        <td>19</td>
      </tr>
      <tr>
        <td>3</td>
        <td>小红</td>
        <td>18</td>
      </tr>
      <tr>
        <td>4</td>
        <td>小李</td>
        <td>22</td>
      </tr>
    </table>

    <script src="jquery/jquery-3.6.1.js"></script>
    <script>
      let odd = $("tbody > tr:odd");
      let even = $("tbody > tr:even");

      odd.css("background-color", "gray");
      even.css("background-color", "green");

      //   for (let i = 0; i < trs.length; i++) {
      //     if (i % 2 == 0) {
      //       $(trs[i]).css("background-color", "gray");
      //     } else {
      //       $(trs[i]).css("background-color", "green");
      //     }
      //   }
    </script>
  </body>
</html>
